<template>
  <div class="p-2">
    <el-row :gutter="20">
      <el-col :lg="24" :xs="24">
        <div v-show="showSearch" class="mb-[10px]">
          <el-card shadow="hover">
            <el-form ref="queryFormRef" :model="queryParams" :inline="true">
              <el-form-item label="任务标题" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入任务标题" clearable
                          @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </el-card>
        </div>

        <el-card shadow="hover">
          <template #header>
            <el-row :gutter="10">
              <el-col :span="1.5">
<!--                <el-button type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>-->
                <el-tag>操作栏</el-tag>
              </el-col>
              <right-toolbar v-model:show-search="showSearch" :columns="columns" :search="true"
                             @query-table="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading" border :data="listData" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="50" align="center" />
            <template v-for="(item, index) in columns">
              <el-table-column v-if="item.visible"
                               :key="item.key"
                               :label="item.label"
                               :width="item.width"
                               align="center"
                               :prop="item.key">
                <template v-slot="scope">
                  <template v-if="item.key === '任务要求' || item.key === '备注' || item.key === '应急原因'">
                    <el-tooltip :content="scope.row[item.key]">
                      <div class="zi-hide">{{ scope.row[item.key] }}</div>
                    </el-tooltip>
                  </template>
                </template>
              </el-table-column>
            </template>

            <el-table-column label="操作" fixed="right" width="260" align="center">
              <template #default="scope">
                <el-button link type="primary" icon="View" @click="handleLook(scope.row)">查看</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            :total="total"
            @pagination="getList"
          />
        </el-card>
      </el-col>
    </el-row>

    <!--  表单  -->
    <formVue ref="formRef"></formVue>
    <!--  发布  -->
    <releaseVue ref="releaseRef"></releaseVue>


    <el-drawer
      v-model="drawer"
      close-on-click-modal
      title="详细信息"
    >
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
        <el-tab-pane label="采样记录" name="1">
          <div class="tabs-card">
            <el-timeline style="max-width: 600px">
              <el-timeline-item
                v-for="(activity, index) in activities"
                :key="index"
                :icon="activity.icon"
                :type="activity.type"
                :color="activity.color"
                :size="activity.size"
                :hollow="activity.hollow"
                :timestamp="activity.timestamp"
              >
                {{ activity.content }}
              </el-timeline-item>
            </el-timeline>
          </div>
        </el-tab-pane>
        <el-tab-pane label="运输记录" name="2">
          <div class="tabs-card">
            <el-timeline style="max-width: 600px">
              <el-timeline-item
                v-for="(activity, index) in activities2"
                :key="index"
                :icon="activity.icon"
                :type="activity.type"
                :color="activity.color"
                :size="activity.size"
                :hollow="activity.hollow"
                :timestamp="activity.timestamp"
              >
                {{ activity.content }}
              </el-timeline-item>
            </el-timeline>
          </div>
        </el-tab-pane>
        <el-tab-pane label="库房信息" name="3">
          <div class="tabs-card">
            <el-timeline style="max-width: 600px">
              <el-timeline-item center placement="top">
                <el-card>
                  <p>转入时间：2025-07-10</p>
                  <h4>当前库房：<el-tag type="success">D区24货架7-10</el-tag></h4>
                  <h4>转入前库房：<el-tag type="warning">C区21货架3-10</el-tag></h4>
                </el-card>
              </el-timeline-item>
              <el-timeline-item center placement="top">
                <el-card>
                  <p>转入时间：2025-07-04</p>
                  <h4>转入库房：<el-tag>C区21货架3-10</el-tag></h4>
                  <h4>转入前库房：<el-tag type="warning">A区3货架1-20</el-tag></h4>
                </el-card>
              </el-timeline-item>
              <el-timeline-item center placement="top">
                <el-card>
                  <p>入库时间：2025-07-03</p>
                  <h4>样品第一次入库：<el-tag>A区3货架1-20</el-tag></h4>
                </el-card>
              </el-timeline-item>
            </el-timeline>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-drawer>

  </div>
</template>

<script setup>
// 方法
import { ref } from 'vue'
import { MoreFilled } from '@element-plus/icons-vue'

// 组件
import formVue from '@/views/samplingAdmin/plan/form.vue'

const formRef = ref(null)
import releaseVue from '@/views/samplingAdmin/plan/release.vue'

const releaseRef = ref(null)
const drawer = ref(false)

// 列显隐信息
const columns = ref([
  { key: '采样标签', label: `采样标签`, visible: true, width: '200', children: [] },
  { key: '任务标题', label: `任务标题`, visible: true, width: '200', children: [] },
  { key: '设备', label: `设备`, visible: true, width: '140', children: [] },
  { key: '任务地点', label: `任务地点`, visible: true, width: '200', children: [] },
  { key: '异常原因', label: `异常原因`, visible: true, width: '150', children: [] },
  { key: '开始时间', label: `开始时间`, visible: true, width: '120', children: [] },
  { key: '预计完成时间', label: `预计完成时间`, visible: true, width: '140', children: [] },
  { key: '任务要求', label: `任务要求`, visible: true, width: '200', children: [] },
  { key: '备注', label: `备注`, visible: true, width: '140', children: [] },
  { key: '创建人', label: `创建人`, visible: true, width: '', children: [] },
  { key: '执行人', label: `执行人`, visible: true, width: '', children: [] },
  { key: '创建时间 ', label: `创建时间`, visible: true, width: '', children: [] },
]);

const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
})
const total = ref(120)
const showSearch = ref(true);
const loading = ref(true);
const listData = ref([
  {
    "采样标签":"CAIYANG202506190006",
    "任务标题": "生活饮用水有机物指标检验",
    "设备": "水质自动采样器",
    "任务地点": "XX 市第二自来水厂水源地",
    "异常原因": "到达不了采样点",
    "开始时间": "2025-07-15",
    "预计完成时间": "2025-07-20",
    "任务要求": "按照 GB 5749-2022 标准，完成 16 项有机物指标检测，重点关注苯、甲苯、二甲苯等指标，提交详细检测报告",
    "备注": "采样容器需使用棕色玻璃瓶，运输过程需避光冷藏",
    "执行人": "陈刚",
    "创建人": "李建国",
    "创建时间": "2025-07-10"
  },
  {
    "采样标签":"CAIYANG202506190004",
    "任务标题": "工业废水有机污染物检测",
    "任务地点": "XX 工业园区污水处理站",
    "设备": "水质自动采样器",
    "异常原因": "到达不了采样点",
    "开始时间": "2025-07-18",
    "预计完成时间": "2025-07-22",
    "任务要求": "检测项目包括化学需氧量（COD）、生化需氧量（BOD5）、挥发酚等有机污染物，采用分光光度法，每 3 小时采样一次，共采集 6 个样品",
    "备注": "采样时需穿戴防腐蚀手套，样品需加硫酸酸化至 pH<2",
    "执行人": "王芳",
    "创建人": "赵志强",
    "创建时间": "2025-07-12"
  },
  {
    "采样标签":"CAIYANG202506190003",
    "任务标题": "地表水重金属指标监测",
    "任务地点": "XX 江干流及支流断面",
    "设备": "水质自动采样器",
    "异常原因": "采样仪器损坏",
    "开始时间": "2025-07-20",
    "预计完成时间": "2025-07-25",
    "任务要求": "监测项目为铜、锌、铅、镉等重金属，每日采样一次，同步测量水温、电导率、浊度",
    "备注": "需使用便携式重金属检测仪现场初筛，采样后 48 小时内完成实验室精确定量",
    "执行人": "刘磊",
    "创建人": "杨红梅",
    "创建时间": "2025-07-14"
  },
  {
    "采样标签":"CAIYANG202506190002",
    "任务标题": "二次供水化学指标检验",
    "任务地点": "XX 大厦高层二次供水水箱",
    "设备": "水质自动采样器",
    "异常原因": "到达不了采样点",
    "开始时间": "2025-07-22",
    "预计完成时间": "2025-07-24",
    "任务要求": "检测余氯、总硬度、氯化物、硫酸盐，每个水箱采集 2 个点位样品，平行检测 3 次",
    "备注": "采样前需放水 3-5 分钟，样品需在常温下保存并于 24 小时内送检",
    "执行人": "周鹏",
    "创建人": "吴伟",
    "创建时间": "2025-07-16"
  },
]);


// 获取数据
const getList = () => {
  loading.value = false
}

// 搜索
const handleQuery = () => {
}

// 重置
const resetQuery = () => {
  for (let i in queryParams.value) {
    if (i !== 'pageNum' && i !== 'pageSize') {
      queryParams.value[i] = undefined
    }
  }
  handleQuery()
}

// 多选
const handleSelectionChange = () => {
}

// 新增
const handleAdd = () => {
  formRef.value.open()
}

// 编辑
const handleEdit = (item) => {
  formRef.value.edit(item)
}

// 发布
const handleRelease = (item) => {
  releaseRef.value.open(item)
}

const activeName = ref('1')
// 查看
const handleLook = () => {
  activeName.value = '1'
  drawer.value = true
}
//
const handleClick = () => {

}
const activities = [
  { content: '从某某区县出发', timestamp: '2025-06-12 10:46', size: 'large', type: 'primary', icon: MoreFilled, },
  { content: '抵达某某区县引用水库', timestamp: '2025-06-12 12:46', color: '#0bbd87', },
  { content: '开始抽检水质信息', timestamp: '2025-06-12 12:50', color: '#0bbd87', },
  { content: '抽检样品完成', timestamp: '2025-06-12 13:50', color: '#0bbd87', },
  { content: '返程', timestamp: '2025-06-12 13:52', type: 'primary', hollow: true, },
]
const activities2 = [
  { content: '从某某区县开始返程', timestamp: '2025-06-13 10:46', size: 'large', type: 'primary', icon: MoreFilled, },
  { content: '抵达运输中心第一站', timestamp: '2025-06-14 12:46', color: '#0bbd87', },
  { content: '抵达运输中心第二站', timestamp: '2025-06-15 12:50', color: '#0bbd87', },
  { content: '抵达运输中心第三站', timestamp: '2025-06-16 12:50', color: '#0bbd87', },
  { content: '抵达运输中心第四站', timestamp: '2025-06-17 12:50', color: '#0bbd87', },
  { content: '抵达仓库', timestamp: '2025-06-18 12:50', type: 'primary', hollow: true, },
]

getList()
</script>
<style lang="scss">
.tabs-card {
  padding: 30px 0px;
}
</style>
